package dao;

import common.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class PwdFromBase {
    private static Connection conn=DataBaseConnect.getConn();
    private static String sql="select password,name,number,phone,birthdate from account where id=?";
    private static PreparedStatement pstmt;
    static {
        try {
            pstmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static String pwd(String id) throws Exception{
        pstmt.setString(1,id);
        ResultSet rs=pstmt.executeQuery();
        while(rs.next()){
            return rs.getString(1);
        }
        return null;
    }
    public static User getInfo(String id){
        try {
            pstmt.setString(1,id);
            ResultSet rs=pstmt.executeQuery();
            while(rs.next()){
                return new User(id,rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return null;
    }
}
